package org.example;

import java.util.*;

public class Test2 {
    public ArrayList<Integer> FindNumbersWithSum(int [] array, int sum) {
        Set<Integer> hash = new HashSet<>();
        ArrayList<Integer> ret = new ArrayList<>();
        for (int i = 0; i < array.length; i++) {
            int target = sum - array[i];
            if (hash.contains(array[i])) {
                ret.add(target);
                ret.add(array[i]);
                break;
            }else {
                hash.add(target);
            }
        }
        return ret;
    }

    public static void main(String[] args) {
        Test2 test2 = new Test2();
        int[] arr = {1,2,3,4,5,6};
        ArrayList<Integer> ret = test2.FindNumbersWithSum(arr,5);
        for (Integer n : ret) {
            System.out.println(n);
        }
    }
}
